using Aurora.TaskScheduler.Abstractions.Message;

namespace Aurora.TaskScheduler.Abstractions.Storage;

/// <summary>
/// 任务存储器
/// </summary>
public interface IDataStorage
{
    /// <summary>
    /// 执行
    /// </summary>
    /// <param name="sql"></param>
    /// <returns></returns>
    Task ExecuteCommand(string sql);
    
    /// <summary>
    /// 获取任务详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    Task<AppTask> GetDetail(string id);


    /// <summary>
    /// 根据名称和分组名称获取任务
    /// </summary>
    /// <param name="taskName"></param>
    /// <param name="groupName"></param>
    /// <returns></returns>
    Task<AppTask> GetTaskByName(string taskName, string groupName);

    /// <summary>
    /// 获取运行日志列表-分页
    /// </summary>
    /// <param name="id"></param>
    /// <param name="page"></param>
    /// <param name="size"></param>
    /// <returns></returns>
    Task<(List<AppTaskLog> list, int total)> GetLogList(string id, int page, int size);


    /// <summary>
    /// 获取运行日志列表-分页
    /// </summary>
    /// <param name="taskName"></param>
    /// <param name="page"></param>
    /// <param name="size"></param>
    /// <param name="groupName"></param>
    /// <returns></returns>
    Task<(List<AppTaskLog> list, int total)> GetLogList(string groupName,string taskName, int page, int size);
    /// <summary>
    /// 获取所有的job
    /// </summary>
    /// <returns></returns>
    Task<List<AppTask>> GetAllJob(bool containerOne = false);
    
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    Task<string> Add(AppTask task);
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="tasks"></param>
    /// <returns></returns>
    Task<string> Add(List<AppTask> tasks);
    
    /// <summary>
    /// 添加
    /// </summary>
    /// <param name="log"></param>
    /// <returns></returns>
    Task<string> AddLog(AppTaskLog log);
    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    Task<bool> Update(AppTask task);
    
    /// <summary>
    /// 更新
    /// </summary>
    /// <param name="tasks"></param>
    /// <returns></returns>
    Task<bool> Update(List<AppTask> tasks);
    /// <summary>
    /// 移除
    /// </summary>
    /// <param name="task"></param>
    /// <returns></returns>
    Task<bool> Remove(AppTask task);


    /// <summary>
    /// 根据任务类型获取列表
    /// </summary>
    /// <param name="taskType"></param>
    /// <returns></returns>
    Task<List<AppTask>> GetListByTaskType(int taskType);


    /// <summary>
    /// 获取最后一次的运行时间
    /// </summary>
    /// <param name="taskName"></param>
    /// <param name="groupName"></param>
    /// <returns></returns>
    Task<AppTaskLog> GetLastLog(string taskName, string groupName);

    /// <summary>
    /// 获取过期的日志信息
    /// </summary>
    /// <param name="expireTime">过期的时间</param>
    /// <param name="page">页码</param>
    /// <param name="size">页容量</param>
    /// <returns></returns>
    Task<(List<AppTaskLog> list,int total)> GetExpireLog(DateTime expireTime, int page, int size);

    Task<bool> RemoveLog(string id);


    Task<bool> RemoveLogRange(List<string> ids);
}